import java.util.Scanner;
//class BankAccount{
//    private int balance;
//    static int accountNumber=0;
//    BankAccount(){
//        this.balance=0;
//        accountNumber++;
//    }
//    BankAccount(int balance){
//        this.balance=balance;
//        accountNumber++;
//    }
//    public int getBalance(){
//        return balance;
//    }
//  public void withdraw(int amount){
//        if(this.balance<amount){
//            System.out.println("Invalid Amount");
//        }else{
//            this.balance-=amount;
//        }
//  }
//  public void deposit(int amount){
//      if(this.balance<amount){
//          System.out.println("Invalid Amount");
//      }else{
//          this.balance+=amount;
//      }
//  }
//    public static int getAccountNumber() {
//        return accountNumber; // 返回账户总数
//    }
//}
//public class Main {
//
//    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        boolean choice1 = scanner.nextBoolean();
//        //是否创建对象
//        if (choice1==true)
//        {
//            //账户1
//            BankAccount myAccount1=new BankAccount();
//            //账户2
//            BankAccount myAccount2=new BankAccount(100);
//            //选择操作类型
//            int choice2 = scanner.nextInt();
//            switch(choice2){
//                case 0://存款
//                    int depositAmount=scanner.nextInt();
//                    myAccount2.deposit(depositAmount);
//                    break;
//                case 1://取款
//                    int withdrawAmount=scanner.nextInt();
//                    myAccount2.withdraw(withdrawAmount);
//                    break;
//            }
//
//            System.out.println(myAccount2.getBalance());
//        }
//
//        System.out.println(BankAccount.accountNumber);
//        scanner.close();
//    }
//
//}

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Scanner;
import java.util.Comparator;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Book[] books = new Book[4];
        //1. 从键盘接收用户输入的4本书的名称（仅有英文字符构成）、出版日期（格式：1998-10-09）、价格，生成Book对象，构造包含4本书的数组
        for(int i=0;i<4;i++){
            String name = scan.next();
            String date_str = scan.next();
            Date date = null;
            //将键盘录入的日期字符串转换为Date
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                date = sdf.parse(date_str);
            } catch (ParseException e) {
                System.out.println("日期格式有误");;
            }

            double price = Double.parseDouble(scan.next());

            Book book = new Book(name, date, price);
            books[i] = book;
        }

        //2.将books按照出版日期降序排序；然后输出books
        Arrays.sort(books, new BookComparatorByPubDate());
        for(Book book:books){
            System.out.println(book);
        }

        //3.将books按照价格升序排序，如果价格相同，则按照书名字母顺序排列。然后输出books
        Arrays.sort(books, new BookComparatorByPrice());
        for(Book book:books){
            System.out.println(book);
        }

        scan.close();
    }

}
class  Book{
    private  String name;
    private  Date date;
    private  double price;
    public Book(String name,Date date,double price){
        this.name=name;
        this.date=date;
        this.price=price;
    }

    public String getName() {
        return name;
    }

    public Date getDate() {
        return date;
    }

    public double getPrice() {
        return price;
    }
    public String toString(){
        return "书名:"+name+",定价:"+price;
    }

}
class BookComparatorByPrice implements Comparator<Book> {
    @Override
    public int compare(Book book1,Book book2) {
        if (book1.getPrice() != book2.getPrice()) {
            return Double.compare(book1.getPrice(), book2.getPrice());
        }
        return book1.getName().compareTo(book2.getName());
    }
}
class BookComparatorByPubDate implements Comparator<Book> {
    @Override
    public int compare(Book book1, Book book2) {
        // 按出版日期降序排序
        return book2.getDate().compareTo(book1.getDate());
    }
}